import { onScopeDispose } from 'vue'
import bus from '@/libs/bus'

// 控件容器 phone 视图
export default function usePhoneView() {
    const scrollTopEventName = 'phone-scroll-top'
    const setScrollTop = top => {
        bus.emit(scrollTopEventName, top)
    }
    const onScrollTop = callback => {
        bus.on(scrollTopEventName, callback)

        onScopeDispose(() => {
            bus.off(scrollTopEventName, callback)
        })
    }

    const scrollTopIdEventName = 'phone-scroll-top-id'
    const setScrollTopId = id => {
        bus.emit(scrollTopIdEventName, id)
    }
    const onScrollTopId = callback => {
        bus.on(scrollTopIdEventName, callback)
        
        onScopeDispose(() => {
            bus.off(scrollTopIdEventName, callback)
        })
    }

    return {
        setScrollTop,
        onScrollTop,

        setScrollTopId,
        onScrollTopId
    }
}